//
//  LXLMultiPhotoTableViewController.m
//  FZAH
//
//  Created by 李小龙 on 17/3/24.
//  Copyright © 2017年 zdqk. All rights reserved.
//

#import "LXLMultiPhotoTableViewController.h"
#import "LXLMultiPhotoCollectionViewController.h"

@interface LXLMultiPhotoTableViewController ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *backButton;

@end

@implementation LXLMultiPhotoTableViewController

//- (instancetype)init {
//    self = [super init];
//    if (self) {
//        self.allGroupsArr = [[NSMutableArray alloc] init];
//    }
//    return self;
//}
- (NSMutableArray *)allGroupsArr {
    if (!_allGroupsArr) {
        _allGroupsArr = [[NSMutableArray alloc] init];
    }
    return _allGroupsArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

//    self.navigationItem.titleView = [self titleViews:@"相册"];
//    [self zimNavBackAction];
    
    [self.backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
}
- (void)backAction {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.allGroupsArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 1.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    static NSString *allGroupsIdentifier = @"allGroupsIdentifier";
    LXLMultiGroupsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:allGroupsIdentifier];
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"LXLMultiGroupsTableViewCell" owner:self options:nil];
    if (nib.count > 0) {
        self.customCell = [nib firstObject];
        cell = self.customCell;
    }
    
    // Configure the cell...
    [cell.groupsImage setImage:[UIImage imageWithCGImage:[_allGroupsArr[indexPath.row] posterImage]]];
    NSString *name = [_allGroupsArr[indexPath.row] valueForProperty:ALAssetsGroupPropertyName];
    [cell.groupsName setText:[NSString stringWithFormat:@"%@(%ld)",name,(long)[_allGroupsArr[indexPath.row] numberOfAssets]]];
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here, for example:
    // Create the next view controller.
    LXLMultiPhotoCollectionViewController *detailViewController = [[LXLMultiPhotoCollectionViewController alloc] init];
    detailViewController.assetsGroup = self.allGroupsArr[indexPath.row];
    // Pass the selected object to the new view controller.
    detailViewController.selectNum = self.selectNum;
    detailViewController.maxNum = self.maxNum;
    // Push the view controller.
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self presentViewController:detailViewController animated:YES completion:^{
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
//    [self.navigationController pushViewController:detailViewController animated:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
